gtk/textview: Improve check for cursor-mode
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 6 Nov 2020 13:30:18 +0000 (14:30 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Fri, 6 Nov 2020 13:30:18 +0000 (14:30 +0100)
Check the text handle role, instead of looking for the other handle
visibility. The other handle may be invisible during selection mode
(e.g. pointing to offscreen contents). This fixes both this code
switching to cursor mode out of the blue, and possible crashes later
on as this handle might be hidden in the process, while its own event
controller is handling events on the parent surface.

gtk/gtktextview.c

index dec6ec64dac2fe8d158cf79c44a1dd239218a598..22f6d84b71088656b099e8f79ac4a8a647aee226 100644 (file)
@@ -5116,7 +5116,7 @@ gtk_text_view_handle_dragged (GtkTextHandle *handle,
       *old_iter = iter;
 
       if (handle == priv->text_handles[TEXT_HANDLE_CURSOR] &&
-          !gtk_widget_is_visible (GTK_WIDGET (priv->text_handles[TEXT_HANDLE_SELECTION_BOUND])))
+          gtk_text_handle_get_role (priv->text_handles[TEXT_HANDLE_CURSOR]) == GTK_TEXT_HANDLE_ROLE_CURSOR)
         gtk_text_buffer_place_cursor (buffer, &cursor);
       else
         gtk_text_buffer_select_range (buffer, &cursor, &bound);